package com.limm.cloud02.controller;


import com.limm.cloud02.entity.Dept;
import com.limm.cloud02.service.impl.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author LiMM
 * @since 2021-09-09
 */
@RestController
@RequestMapping("/cloud/dept")
public class DeptController {



    @Autowired
    DeptService service;

    @Autowired
    private DiscoveryClient client;

    @GetMapping("/selectByID/{dept_no}")
    public Dept selectByID(@PathVariable Long dept_no){

        final Dept id1 = service.getById(dept_no);
        return id1;
    }

    @GetMapping("/findAll")
    public List<Dept> findAll(){

        return service.list();
    }

    @GetMapping("/eurekaClient")
    public Object discovery(){
        final List<String> services = client.getServices();
        System.out.println("discovery=>services: "+services);
        final List<ServiceInstance> instances = client.getInstances("SPRINGCLOUD-API");

        for (ServiceInstance instance : instances) {
            System.out.println(
                    instance.getHost()+"\t"+
                            instance.getPort()+"\t"+
                            instance.getUri()+"\t"+
                            instance.getMetadata()+"\t"+
                            instance.getInstanceId()+"\t"+
                            instance.getServiceId()+"\t"

            );
        }
        return this.client;
    }

}

